package site.xuqing.autohelperscript;

import java.util.ArrayList;
import java.util.List;

import site.xuqing.autohelper.bean.StepBean;
import site.xuqing.autohelper.bean.StepContainerBean;
import site.xuqing.autohelper.bean.StepInfoBean;
import site.xuqing.autohelper.type.ScrollType;
import site.xuqing.autohelper.type.StepType;
import site.xuqing.autohelperscript.script.StepScriptInput;

/**
 * common script
 * 脚本管理，用户自定义
 *
 * @author XuQing
 */
public class ScriptManager {
    
    /**
     * 返回
     */
    public static StepContainerBean getStepBack() {
        StepContainerBean stepContainerBean = new StepContainerBean();
        stepContainerBean.setName("返回");
        List<StepBean> stepBeans = new ArrayList<>();
        //返回
        stepBeans.add(new StepBean(StepType.RETURN));
        stepContainerBean.setStepBeans(stepBeans);
        return stepContainerBean;
    }
    
    /**
     * 滑动
     */
    public static StepContainerBean getStepScroll(ScrollType direction) {
        StepContainerBean stepContainerBean = new StepContainerBean();
        stepContainerBean.setName("翻页");
        List<StepBean> stepBeans = new ArrayList<>();
        switch (direction) {
            case UP:
                stepBeans.add(new StepBean(StepType.UP_SCROLL));
                break;
            case DOWN:
                stepBeans.add(new StepBean(StepType.DOWN_SCROLL));
                break;
            case LEFT:
                stepBeans.add(new StepBean(StepType.LEFT_SCROLL));
                break;
            case RIGHT:
                stepBeans.add(new StepBean(StepType.RIGHT_SCROLL));
                break;
            default:
        }
        stepContainerBean.setStepBeans(stepBeans);
        return stepContainerBean;
    }
    
    /**
     * 点击界面上第一个输入框，并输入
     */
    public static StepContainerBean getStepInput() {
        StepContainerBean stepContainerBean = new StepContainerBean();
        stepContainerBean.setName("点击输入框并输入");
        List<StepBean> stepBeans = new ArrayList<>();
        stepBeans.add(new StepBean(StepType.CUSTOM).setStepScript(new StepScriptInput()));
        stepContainerBean.setStepBeans(stepBeans);
        return stepContainerBean;
    }
    
    /**
     * 点击文本为clickText的按钮或者能点击的控件
     */
    public static StepContainerBean getStepClick(String clickText) {
        StepContainerBean stepContainerBean = new StepContainerBean();
        stepContainerBean.setName("点击按钮");
        List<StepBean> stepBeans = new ArrayList<>();
        stepBeans.add(new StepBean(StepType.SINGLE_FIRST_TAP).setStepInfo(new StepInfoBean(clickText, "", "", "")));
        stepContainerBean.setStepBeans(stepBeans);
        return stepContainerBean;
    }
}
